package com.taiji.dicom4cloud.common.security.config;

import com.taiji.dicom4cloud.common.core.utils.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description
 * @Author fanxl
 * @Date 2021/5/26
 **/
@Slf4j
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //第一个方法设置访问路径前缀，第二个方法设置资源路径
        registry.addResourceHandler("/static/**").addResourceLocations(getStaticPath());
    }
    /**
     * 取得静态资源路径
     *
     * @return
     */
    public String getStaticPath() {
        String path = FileUtil.getStaticPath();
        path = "file:/" + path.replace("/target/classes/", "");
        path = path.replace("file://", "file:/");
        log.info(path);
        return path;
    }
}
